import { request } from 'app/http'
import { toPasswordParam } from 'app/converter'

const PATH = '/company/auth'

export function login(data) {
  return request({
    url: PATH + '/login',
    method: 'post',
    data: toPasswordParam(data),
    showErr: true
  })
}

export function fillup(data) {
  return request({
    url: PATH + '/fillup',
    method: 'post',
    data,
    showErr: true
  })
}

export function findPwdUpdateCompany(data) {
  const { password, password2 } = data
  if (password !== password2) {
    return Promise.reject({ msg: '密码和确认密码不一致' })
  }
  return request({
    url: PATH + '/findPwdUpdate',
    method: 'post',
    data: toPasswordParam(data)
  })
}
export function findPwdVerifyCompany(data) {
  return request({
    url: PATH + '/findPwdVerify',
    method: 'post',
    data,
    showErr: true
  })
}

export function getCompanyInfo() {
  return request({
    url: PATH + '/info',
    method: 'get',
    showLoading: true
  })
}

export function logout() {
  return request({
    url: PATH + '/logout',
    method: 'delete',
    showErr: true
  })
}

export function register(data) {
  const { password, password2 } = data
  if (password !== password2) {
    return Promise.reject({ msg: '密码和确认密码不一致' })
  }
  return request({
    url: PATH + '/register',
    method: 'post',
    data: toPasswordParam(data)
  })
}
